import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
Vue.prototype.url = {
	 baseUrl: "http://192.168.137.1:8088/",
	 wsUrl: "ws://192.168.137.1:8088/"
}
Vue.prototype.ajax = function(url, method, data, fun) {
	console.log(uni.getStorageSync("token"))
	uni.request({
		"url": url,
		"method": method,
		"header": {
			token: uni.getStorageSync("token")
		},
		"data": data,
		success: function(r) {
			console.log(r.statusCode + ":" + r.data.code)
			if (r.statusCode == 401 && r.data.code != 200) {
				uni.removeStorageSync("token")
				uni.redirectTo({
					url: "/pages/login/login"
				})
			} else if (r.statusCode == 200 && r.data.code == 200) {
				let data = r.data
				if (data.hasOwnProperty("token")) {
					let token = data.token
					uni.setStorageSync("token", token)
				}
				fun(r)
			} else if (r.statusCode == 200 && r.data.code == 505) {
				uni.showToast({
					icon: 'none',
					title: r.data.msg
				})
				setTimeout(() => {
					uni.redirectTo({
						url: "/pages/bind/bind"
					})
				}, 2000)

			} else {
				uni.showToast({
					icon: 'none',
					title: r.data.msg
				})
			}
		}
	})
}
